import styled from "@emotion/styled"
import { useState } from "react"
import Svg, { SvgComponent } from "@/components/base/Svg"
import Image from "@/components/base/Image"
import ButtonRegular from "@/components/composite/ButtonRegular/main"
import { Invalid } from "./WelfareBonusCard"

const RectangleLeftActiveBg = styled(SvgComponent("pages/Walfare/svg/rectangle_left_active.svg"))`
    position: absolute;
    top: -8rem;
    left: -1px;
    width: 375rem;
    height: 200rem;
    z-index: 0;
    & > svg {
        width: 100%;
        height: 100%;
        preserveaspectratio: "none";
    }
`
const RectangleRightActiveBg = styled(SvgComponent("pages/Walfare/svg/rectangle_right_active.svg"))`
    position: absolute;
    top: -8rem;
    width: 100%;
    height: 200rem;
    z-index: 0;
    & > svg {
        width: 100%;
        height: 100%;
        preserveaspectratio: "none";
    }
`

/**
 * 卡片容器组件
 * @param tabType - 当前选中的标签类型：'general' | 'vip'
 */
const CardBox = styled.div<{ tabType: "general" | "vip" }>`
    height: 100%;
    width: 100%;
    // 头部样式
    .header {
        height: 56rem;
        display: flex;
        width: 100%;
        position: relative;
        justify-content: space-around;
        align-items: center;
        // 标签按钮样式
        > div {
            width: 50%;
            height: 20rem;
            z-index: 3;
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 8px;
            margin-top: -20rem;
            img {
                width: 17rem;
                height: 17rem;
            }
            span {
                font-weight: 700;
                font-size: 14rem;
                color: #131416;
            }
            z-index: 1;
        }
        // 通用奖励标签
        .general-header {
            width: 50%;
            z-index: 1;
        }
        // VIP奖励标签
        .vip-header {
            width: 50%;
            z-index: 1;
        }
        // 标签背景色
        &::before {
            content: "";
            width: 50%;
            height: 90%;
            position: absolute;
            background: ${(props) => (props.tabType === "general" ? "#fff" : "#ffd8dc")};
            top: -4rem;
            ${(props) => (props.tabType === "general" ? "right: 0;" : "left: 0;")}
            border-top-left-radius: ${(props) => (props.tabType === "general" ? " 10rem" : 0)};
            border-top-right-radius: ${(props) => (props.tabType !== "general" ? " 10rem" : 0)};
            background-size: 100%;
            background-repeat: no-repeat;
            z-index: 0;
        }
    }
    // 内容区域样式
    .content {
        padding: 0 16rem;
        z-index: 1;
        position: relative;
        min-height: 250rem;
        background: #fff;

        // 通用奖励内容
        .general-box {
            height: 136rem;
            border-radius: 8rem;
            overflow: hidden;
            img {
                width: 100%;
                height: 100%;
            }
        }
        // VIP奖励卡片列表
        .vip-box {
            > div {
                margin-bottom: 8rem;
            }
        }
    }
`

/**
 * VIP奖励卡片组件
 */
const VipCardBox = styled.div`
    width: 100%;
    height: 120rem;
    border-radius: 10rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20rem 16rem;
    gap: 16rem;
    position: relative;
    overflow: hidden;
    .card-bg {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 0;
    }
    // 左侧图标区域
    & > .left {
        position: relative;
        z-index: 1;
        img {
            width: 80rem;
            height: 80rem;
        }
    }
    // 右侧内容区域
    & > .right {
        position: relative;
        z-index: 1;
        width: 100%;
        // 标题区域
        .title {
            width: 100%;
            height: 20rem;
            line-height: 20rem;
            margin-bottom: 9rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            span {
                font-size: 14rem;
                font-weight: 700;
                color: #131416;
            }
            img {
                width: 15rem;
                height: 15rem;
            }
        }
        // 金额描述区域
        .money-dec {
            font-size: 12rem;
            height: 16rem;
            line-height: 16rem;
            font-weight: 400;
            display: flex;
            align-items: center;
            gap: 5rem;
            margin-bottom: 11rem;
            .money {
                font-size: 16rem;
                color: #f50016;
                font-weight: 500;
            }
        }
        // 底部区域
        .footer {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
    }
`

/**
 * 按钮样式组件
 */
const ButtonRegularBox = styled(ButtonRegular)`
    background: #f5dbaa !important;
    box-shadow: none;
    width: 88rem !important;
    height: 24rem;
    font-size: 12rem;
    font-weight: 500 !important;
    padding: 0;
    color: #131416;
`

/**
 * 奖励卡片组件
 * 包含通用奖励和VIP奖励两种类型
 */
export default function BonusRewardsCard() {
    // 当前选中的标签类型
    const [tabType, setTabType] = useState<"general" | "vip">("general")

    return (
        <CardBox tabType={tabType}>
            {/* 头部标签区域 */}
            <div className="header">
                {tabType === "general" ? (
                    <RectangleLeftActiveBg preserveAspectRatio="none" />
                ) : (
                    <RectangleRightActiveBg preserveAspectRatio="none" />
                )}
                <div
                    // onClick={() => setTabType("general")}
                    className="general-header"
                >
                    <Svg src="pages/Walfare/svg/general_bonus.svg" />
                    <span>General Bonus</span>
                </div>
                <div
                    // onClick={() => setTabType("vip")}
                    className="vip-header"
                >
                    <Svg src="pages/Walfare/svg/vip_bonus.svg" />
                    <span>VIP Bonus</span>
                </div>
            </div>

            {/* 内容区域 */}
            <div className="content">
                {tabType === "general" ? (
                    // 通用奖励内容
                    <div className="general-box">
                        <Image src="pages/Walfare/images/welfare_list_mystery.webp" />
                    </div>
                ) : (
                    // VIP奖励卡片列表
                    <div className="vip-box">
                        {/* VIP奖励卡片1 */}
                        <VipCardBox>
                            <Svg
                                className="card-bg"
                                src="pages/Walfare/svg/bg.svg"
                            />
                            <div className="left">
                                <Svg src="pages/Walfare/svg/red_packet.svg" />
                            </div>
                            <div className="right">
                                <div className="title">
                                    <span>VIP Bonus</span>
                                    <Svg src="pages/Walfare/svg/question.svg" />
                                </div>
                                <div className="money-dec">
                                    <span className="before">Get</span>
                                    <span className="money">₱ 500</span>
                                    <span className="after">for free</span>
                                </div>
                                <div className="footer">
                                    <Invalid />
                                    <ButtonRegularBox>Get Now</ButtonRegularBox>
                                </div>
                            </div>
                        </VipCardBox>
                        {/* VIP奖励卡片2 */}
                        <VipCardBox>
                            <Svg
                                className="card-bg"
                                src="pages/Walfare/svg/bg.svg"
                            />
                            <div className="left">
                                <Svg src="pages/Walfare/svg/rebate.svg" />
                            </div>
                            <div className="right">
                                <div className="title">
                                    <span>VIP Bonus</span>
                                    <Svg src="pages/Walfare/svg/question.svg" />
                                </div>
                                <div className="money-dec">
                                    <span className="money">₱ 500</span>
                                </div>
                                <div className="footer">
                                    <div />
                                    <ButtonRegularBox>Get Now</ButtonRegularBox>
                                </div>
                            </div>
                        </VipCardBox>
                    </div>
                )}
            </div>
        </CardBox>
    )
}
